#!/bin/bash

del_ksf_array=("_agentka.ksf" "_agentkb.ksf")
del_kms_array=("kmsagent.conf" "kmsconf.ksf" "backup_kmsconf.ksf")
function UninstallKmsagent() {
    for kms_param in "${del_kms_array[@]}"; do
        if [ -f ${kmsagent_work_path}/${kms_param} ]; then
            rm -f ${kmsagent_work_path}/${kms_param}
        fi
    done
    for ksf_param in "${del_ksf_array[@]}"; do
        rm -f ${kmsagent_work_path}/data/*${ksf_param}
    done
    [ -d "${kmsagent_work_path}/data" ] && [ `ls "${kmsagent_work_path}/data" | wc -l` -eq 0 ] && rm -rf ${kmsagent_work_path}/data
    [ -d "${kmsagent_work_path}" ] && [ `ls "${kmsagent_work_path}" | wc -l` -eq 0 ] && rm -rf ${kmsagent_work_path}
}

function usage() {
    echo "Usage:"
    echo "     kmsagent_uninstall.sh [kmsagent_work_path]"
    exit -1
}

if [ $# -ne 1 ]; then
    echo "Incorrect number of parameters."
    usage
fi

kmsagent_work_path=$1
if [ ! -d ${kmsagent_work_path} ]; then
    echo "[WARNING] The kmsagent work path does not exist."
    exit -1
fi

UninstallKmsagent
